/**
 * InsCube Decoder Program
 * @author Bao Linfeng
 * Copyright(R) 2022~2025
 */

#include<gflags/gflags.h>
#include "Decoder.h"

DEFINE_string(460, "", "for device ADIS16465");
DEFINE_string(465, "", "for device ADIS16460");
DEFINE_string(cpt, "", "for device SPAN CPT");
DEFINE_string(rst, "", "for device INS-Cube Result file");

#include <iostream>
int main(int argc, char **argv) {
  google::ParseCommandLineFlags(&argc, &argv, true);
  if (!fLS::FLAGS_460.empty()) {
	InsCube::RawDecoder raw_decoder{InsCube::Adis16460Handle()};
	std::string rawpath = fLS::FLAGS_460;
	std::string imupath = rawpath + ".imutxt";
	std::string imdpath = rawpath + ".imd";
	std::string gnss = rawpath + ".gnsstxt";
	std::string vel = rawpath + ".veltxt";
	std::string rst = rawpath + ".rst";
	std::string bmp = rawpath + ".bmptxt";
	raw_decoder.Load(rawpath);
	raw_decoder.SaveToImu(imupath);
	raw_decoder.SaveToImd(imdpath);
	raw_decoder.SaveToGnss(gnss);
	raw_decoder.SaveToVel(vel);
	raw_decoder.SaveToRst(rst);
	raw_decoder.SaveToBmp(bmp);
  }
  if (!fLS::FLAGS_465.empty()) {
	InsCube::RawDecoder raw_decoder{InsCube::Adis16465Handle(125, 9.801619165022489)};
	std::string rawpath = fLS::FLAGS_465;
	std::string imupath = rawpath + ".imutxt";
	std::string imdpath = rawpath + ".imd";
	std::string gnss = rawpath + ".gnsstxt";
	std::string vel = rawpath + ".veltxt";
	std::string rst = rawpath + ".rst";
	std::string bmp = rawpath + ".bmptxt";
	raw_decoder.Load(rawpath);
	raw_decoder.SaveToImu(imupath);
	raw_decoder.SaveToImd(imdpath);
	raw_decoder.SaveToGnss(gnss);
	raw_decoder.SaveToVel(vel);
	raw_decoder.SaveToRst(rst);
	raw_decoder.SaveToBmp(bmp);
  }
  if (!fLS::FLAGS_cpt.empty()) {
	InsCube::CptDecoder cpt;
	cpt.Load(fLS::FLAGS_cpt);
  }
  if(!fLS::FLAGS_rst.empty()){
    InsCube::RstDecoder rst;
    rst.Load(fLS::FLAGS_rst);
    rst.SaveToRstTxt(fLS::FLAGS_rst + ".rt.nav");
  }
  return 0;
}
